﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using RedandBlue.RepositoryPattern.EF6;

namespace QuickPrompt.DomainModel
{
    public partial class Prompt : Entity
    {
        public Prompt()
        {
            PromptTimeZone = TimeZoneInfo.Local.Id;
        }
        [Key, ScaffoldColumn(false), Column(Order = 1), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        /// <summary>
        /// Email or Phone
        /// </summary>
        [Column(Order = 2),
         Required(ErrorMessage = "{0} is required"),
         Display(Name = "Delivery Address"),
         RegularExpression(@"(\(?\d{3}\)?-? *\d{3}-? *-?\d{4})|(^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$)",
             ErrorMessage = "Invalid {0}"), Index("IX_PromptByNote", 3, IsUnique = true)]
        public string AddressValue { get; set; }

        [Column(Order = 3),
         ScaffoldColumn(false), 
            Index("IX_PromptByNote", 1, IsUnique = true)]
        public int NoteId { get; set; }

        [Column(Order = 4),
         Required(ErrorMessage = "{0} is required"),
         Display(Name = "Type")]
        [UIHint("PromptTypeEditor")]
        public PromptType PromptType { get; set; }

        [Column(Order = 5),
         Display(Name = "Reminder Timezone"),
         Required(ErrorMessage = "Please select your {0}")]
        [UIHint("PromptTimeZoneEditor")]
        public string PromptTimeZone { get; set; }

        [NotMapped]
        public TimeZoneInfo TimeZone
        {
            get { return TimeZoneInfo.FindSystemTimeZoneById(PromptTimeZone); }
            set { PromptTimeZone = value == null ? TimeZoneInfo.Local.Id : value.Id; }
        }

        [Column(Order = 6),
         Display(Name = "Frequency"),
         Required(ErrorMessage = "Please select your {0}"), Index("IX_PromptByNote", 2, IsUnique = true)]
        [UIHint("PromptFrequencyEditor")]
        public PromptFrequency PromptFrequency { get; set; }

        [Display(Name = "Starting From")]
        public DateTime StartingFromUtc { get; set; }

        [ScaffoldColumn(false)]
        public DateTime? LastPromptedUtc { get; set; }

        [ForeignKey("NoteId")]
        public virtual QuickNote QuickNote { get; set; }

    }
}
